# ----------------------------------------------------------------------
#  The information and source code contained herein is the
#  exclusive property of Karthikeyan and Samuel vijaykumar.
#  No part of this software may be used, reproduced, stored or distributed in any form
#  without explicit written authorization from the authors.
# ----------------------------------------------------------------------

from types import *
from inspect import *

def describeMethod(name,write=0):
	"""
  	Describe the method with its arguments
  	"""

	if type(name) == MethodType :
		print '\tMethod: %s' % name.__name__

  	if type(name) == FunctionType :
		print '\t\tFunction: %s' % name.__name__

  	if type(name) == UnboundMethodType :
		print '\tUnboundMethodType: %s' % name.__name__

  	describeArgs(name)

def describeArgs(name):
	"""
  	Describe the arguments for every entry
  	"""
  	try:
    		arginfo = getargspec(name)
  	except TypeError:
    		return 0

  	myargs = arginfo [0]
  	posargs = arginfo [1]

  ###base arguments
	if myargs :
    		if arginfo[0] == 'self' :
      			print "    Instance Method(self): %s"%name.__name__
      			myargs.pop(0)
    		print "Method Arguments: %s" %','.join(myargs)
    		#predictype(name, arginfo[0])

    ###scanning for default arguments
    	if arginfo[3]:
		deflen = len(arginfo[3])
		baselen = len(myargs)
		defargs = myargs[baselen-deflen:baselen]
		defvals  = zip(defargs, arginfo[3])
		for grp in defvals:
        		print '        Default Value set for %s is "%s"'%(grp[0],grp[1])


	if  arginfo[1] == None :
    		pass
  	elif arginfo[1] == 'args' :
    		pass
  	else :
    		print "    Positional Argument Parameters: %s" %arginfo[1]
	
	if  arginfo[2] == None :
    		pass
  	elif arginfo[2] == 'kwargs' :
    		pass
  	else :
    		print "    Keyword Argument Parameters: %s" %arginfo[2]

def predictype(meth, argroup):
	"""
  	Predict the type of the argument
  	"""
  	etypes = ['int','Int','integer','Integer','char','Char','character','Character','string','String','float','Float','bool','Bool','Boolean','boolean']
  	argnum = argroup.__len__()
  	if argnum == 0 :
  		pass
  	else  :
  		try :
   			meth('12')
  		except Exception,  E:
    			print E
    		if "least" and "exactly" in E :
      			print "######TypeError encountered"
    		else :
     			 print "#######someother error"
